package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.AgentProtocolMapperExt;
import com.lzy.product.dtos.agent.AgentProtocolDto;
import com.lzy.product.entity.AgentProtocol;
import com.lzy.product.service.AgentProtocolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AgentProtocolServiceImpl implements AgentProtocolService {

    @Autowired
    private AgentProtocolMapperExt agentProtocolMapperExt;


    @Override
    public Long insert(AgentProtocolDto dto) {
        AgentProtocol agentProtocol = DozerUtils.map(dto, AgentProtocol.class);
        return agentProtocolMapperExt.insertSelective(agentProtocol) > 0 ? agentProtocol.getId() : 0;
    }

    @Override
    public Boolean update(AgentProtocolDto dto) {
        return agentProtocolMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, AgentProtocol.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return null;
    }

    @Override
    public Boolean remove(Long id) {
        return null;
    }

    @Override
    public AgentProtocolDto findById(Long id) {
        return DozerUtils.map(agentProtocolMapperExt.selectByPrimaryKey(id), AgentProtocolDto.class);
    }

    @Override
    public List<AgentProtocolDto> query(AgentProtocolDto dto) {
        return null;
    }

    @Override
    public PageInfo<AgentProtocolDto> selectList(Pager pager, AgentProtocolDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<AgentProtocolDto> list = agentProtocolMapperExt.selectList(dto);
        return new PageInfo<>(list);
    }

    @Override
    public List<AgentProtocolDto> queryList() {
        return agentProtocolMapperExt.queryList();
    }

    @Override
    public AgentProtocolDto selectDetailById(Long id) {
        return agentProtocolMapperExt.selectDetailById(id);
    }
}
